package com.livecooking;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;

public class DetailsActivity extends Activity{
	
	public static final String HOW_TO_MAKE = "howToMake";
	public static final String FOOD_NAME = "foodName";
	public static final String IMV_HOW_TO_MAKE = "Id";
	public static final String BOOKMARK = "Bookmark";
	
	FoodsDataSource datasource;
	
	Button bntBookmark;
	Integer bookmark;
	Integer Id;
	public GetImages getIma;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.details);
		
		datasource = new FoodsDataSource(this);
		datasource.open();
		
		String foodName = this.getIntent().getStringExtra(FOOD_NAME);
		String howToMake = this.getIntent().getStringExtra(HOW_TO_MAKE);
		String imHowToMake = this.getIntent().getStringExtra(IMV_HOW_TO_MAKE);
		String txtbookmark = this.getIntent().getStringExtra(BOOKMARK);
		
		Id= Integer.parseInt(imHowToMake);
		bookmark = Integer.parseInt(txtbookmark);
		
		setTitle(foodName);
		bntBookmark = (Button)findViewById(R.id.btnSave);
		if(bookmark==1){
		bntBookmark.setText("Delete Bookmark");
		}
		
		ImageView imvHowToMake = (ImageView) findViewById(R.id.imvHowToMake);
		imvHowToMake.setImageResource(getIma.getImage(Id));
		WebView webHowToMake = (WebView)findViewById(R.id.web);
		webHowToMake.getSettings().setJavaScriptEnabled(true);
		webHowToMake.loadDataWithBaseURL("", howToMake, "text/html", "UTF-8", "");
	}
	public void onClickSave(View v){
		try {
			if(bookmark==0){
				bntBookmark.setText("Delete Bookmark");
				bookmark=1;
				
			}else{
				bntBookmark.setText("Add Bookmark");
				bookmark=0;
			}
//			datasource.update(bookmark, Id);

			datasource.update(bookmark, Id);
		} catch (Exception e) {
			Log.e("error: ", e.toString());
		}
		
	}
}
